import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import get from '@dfeidao/atom-web/local/get';
import fire from '@dfeidao/atom-web/msg/fire';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
// import refresh from '@dfeidao/atom-web/url/refresh';
import a006 from './a006';

export default async function a005(fd: IFeidaoAiBrowserComponent) {// 修改隐患源特性的保存
	// todo
	console.log('zj-000007:a006----start');
	// 获取隐患源编号
	const no = get(fd, 'source1') as string;
	// 获取当前列的隐患源特性编号
	const hno = get(fd, 'hsource') as string;
	console.log('修改隐患源编号', no);
	console.log('修改隐患源特性编号', hno);
	// 获取输入框原始数据
	const odata = get(fd, 'res1') as {
		res: Array<{
			hidden_source_feature_code: string;
			hidden_source_feature_name: string;
			hidden_source_feature_no: string;
			control_data: string;
		}>
	};
	// 获取修改后的输入框数据
	let hdata = get(fd, 'hidden_info1');
	console.log('输入框数据', hdata);
	if (!hdata) {
		hdata = odata.res[0];
	}
	// 获取公司下拉框数据
	const company = fd.data.node.querySelector<HTMLSelectElement>('[data-id="com"]');
	const companyno = company.value;// 获取公司编号
	console.log('获取公司编号', companyno);
	let company_name = "";
	if (companyno === '请选择') {
		alert('请完善信息');
		return;
	} else {
		company_name = company.selectedOptions[0].text;
	}
	// 获取工厂下拉框数据
	const factory = fd.data.node.querySelector<HTMLSelectElement>('[data-id="fac"]');
	const factoryno = factory.value;// 获取工厂编号
	console.log('获取工厂编号', factoryno);
	let factoryname = "";
	if (factoryno === '请选择') {
		alert('请完善信息');
		return;
	} else {
		factoryname = factory.selectedOptions[0].text;
	}
	// 获取控制数据下拉框数据
	const control = fd.data.node.querySelector<HTMLSelectElement>('[data-id="stu"]');
	const controlname = control.value;// 获取控制数据下拉框

	// 保存操作
	const r = await nodejs<{ code: number; result: string }>('wyf-hManager/zj-000008/s002', {

		hidden_source: no,
		hidden_source_feature_no: hno,
		hidden: hdata,
		filter: {
			companyid: companyno,
			companyname: company_name,
			factory_no: factoryno,
			factory_name: factoryname,
			status_manage: controlname
		}

	});
	console.log(r);
	if (r.code === 1) {
		alert('保存成功');
		await a006(fd);
		fire('zj-000006', 'a001', no);
		// refresh();
	} else {
		alert('保存失败');
	}
	console.log('zj-000007:a006----end');
}
